package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Gnhd;
import com.ruoyi.system.service.IGnhdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公牛后代Controller
 * 
 * @author ruoyi
 * @date 2025-02-15
 */
@RestController
@RequestMapping("/system/gnhd")
public class GnhdController extends BaseController
{
    @Autowired
    private IGnhdService gnhdService;

    /**
     * 查询公牛后代列表
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:list')")
    @GetMapping("/list")
    public TableDataInfo list(Gnhd gnhd)
    {
        startPage();
        List<Gnhd> list = gnhdService.selectGnhdList(gnhd);
        return getDataTable(list);
    }

    /**
     * 导出公牛后代列表
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:export')")
    @Log(title = "公牛后代", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gnhd gnhd)
    {
        List<Gnhd> list = gnhdService.selectGnhdList(gnhd);
        ExcelUtil<Gnhd> util = new ExcelUtil<Gnhd>(Gnhd.class);
        util.exportExcel(response, list, "公牛后代数据");
    }

    /**
     * 获取公牛后代详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:query')")
    @GetMapping(value = "/{公牛号}")
    public AjaxResult getInfo(@PathVariable("公牛号") String 公牛号)
    {
        return success(gnhdService.selectGnhdBy公牛号(公牛号));
    }

    /**
     * 新增公牛后代
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:add')")
    @Log(title = "公牛后代", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gnhd gnhd)
    {
        return toAjax(gnhdService.insertGnhd(gnhd));
    }

    /**
     * 修改公牛后代
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:edit')")
    @Log(title = "公牛后代", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gnhd gnhd)
    {
        return toAjax(gnhdService.updateGnhd(gnhd));
    }

    /**
     * 删除公牛后代
     */
    @PreAuthorize("@ss.hasPermi('system:gnhd:remove')")
    @Log(title = "公牛后代", businessType = BusinessType.DELETE)
	@DeleteMapping("/{公牛号s}")
    public AjaxResult remove(@PathVariable String[] 公牛号s)
    {
        return toAjax(gnhdService.deleteGnhdBy公牛号s(公牛号s));
    }
}
